/**
    入驻小区
**/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            couponShopPoolManageInfo: {
                couponShopPools: [],
                total: 0,
                records: 1,
                moreCondition: false,
                shopId: '',
                conditions: {
                    couponName: '',
                    shopId: vc.getCurrentCommunity().shopId

                }
            }
        },
        _initMethod: function () {
            $that._listCouponShopPools(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {

            vc.on('couponShopPoolManage', 'listCouponShopPool', function (_param) {
                $that._listCouponShopPools(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listCouponShopPools(_currentPage, DEFAULT_ROWS);
            });
            vc.on('chooseCouponPool', 'chooseCouponPool', function (_couponPool) {
                vc.jumpToPage('/#/pages/goods/buyGold?poolId='+_couponPool.poolId);
            });
            vc.on('chooseCouponPoolSend', 'chooseCouponPoolSend', function (_couponPool) {
                vc.jumpToPage('/#/pages/goods/buyGoldSend?spId='+_couponPool.spId);
            });
            vc.on('chooseCouponPoolSendParking', 'chooseCouponPoolSendParking', function (_couponPool) {
                vc.jumpToPage('/#/pages/goods/buyGoldSendParking?spId='+_couponPool.spId);

            });
            
        },
        methods: {
            _listCouponShopPools: function (_page, _rows) {

                $that.couponShopPoolManageInfo.conditions.page = _page;
                $that.couponShopPoolManageInfo.conditions.row = _rows;
                $that.couponShopPoolManageInfo.conditions.caId = vc.getCurrentCommunity().caId;
                var param = {
                    params: $that.couponShopPoolManageInfo.conditions
                };

                //发送get请求
                vc.http.apiGet('couponShopPool.listCouponShopPool',
                    param,
                    function (json, res) {
                        var _couponShopPoolManageInfo = JSON.parse(json);
                        $that.couponShopPoolManageInfo.total = _couponShopPoolManageInfo.total;
                        $that.couponShopPoolManageInfo.records = _couponShopPoolManageInfo.records;
                        $that.couponShopPoolManageInfo.couponShopPools = _couponShopPoolManageInfo.data;
                        vc.emit('pagination', 'init', {
                            total: $that.couponShopPoolManageInfo.records,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddCouponShopPoolModal: function () {
                vc.emit('chooseCouponPool', 'openChooseCouponPoolModel', {});
            },
            _openSendCouponShopPoolModal: function () {
                vc.emit('chooseCouponPoolSend', 'openchooseCouponPoolSendModel', {});
            },
            _openParkingCouponShopPoolModal: function () {
                vc.emit('chooseCouponPoolSendParking', 'openchooseCouponPoolSendParkingModel', {});
            },
            _openEditCouponShopPoolModel: function (_couponShopPool) {
                vc.emit('editCouponShopPool', 'openEditCouponShopPoolModal', _couponShopPool);
            },
            _openDeleteCouponShopPoolModel: function (_couponShopPool) {
                vc.emit('deleteCouponShopPool', 'openDeleteCouponShopPoolModal', _couponShopPool);
            },
            _queryCouponShopPoolMethod: function () {
                $that._listCouponShopPools(DEFAULT_PAGE, DEFAULT_ROWS);

            },
            _moreCondition: function () {
                if ($that.couponShopPoolManageInfo.moreCondition) {
                    $that.couponShopPoolManageInfo.moreCondition = false;
                } else {
                    $that.couponShopPoolManageInfo.moreCondition = true;
                }
            }


        }
    });
})(window.vc);
